package com.iamteer.b_data;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class DataAction extends ActionSupport{

	@Override
	public String execute() throws Exception {
		
		// 1. 请求数据封装
		// 2. 调用 Service 处理数据
		// 3. 数据保存到域中
		//方式 1：直接拿到 ServletAPI
/*		
  		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		ServletContext application = ServletActionContext.getServletContext();
		
		request.setAttribute("request_data", "request");
		session.setAttribute("session_data", "session");
		application.setAttribute("application_data", "application");
*/
		
		// 方式 2：通过 ActionContext 类
		// [解耦的方式实现对数据的操作]
		ActionContext ac = ActionContext.getContext();
		Map<String, Object> request = ac.getContextMap();
		Map<String, Object> session = ac.getSession();
		Map<String, Object> application = ac.getApplication();
		
		request.put("request_data", "request_map");
		session.put("session_data", "session_map");
		application.put("application_data", "application_map");
		
		// 方式 3：见 DataAction1.java
		
		return SUCCESS;
	}
}
